package a10_动态规划;

import java.util.Scanner;

/**
 * <p>
 * a18_完全背包理论基础
 * </p>
 *
 * @author flyduck
 * @since 2025/2/13
 */
public class a18_完全背包理论基础 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int number = scanner.nextInt();
        int totalWeight = scanner.nextInt();

        int[] weight = new int[number];
        int[] value = new int[number];

        for (int i = 0; i < weight.length; i++) {
            weight[i] = scanner.nextInt();
            value[i] = scanner.nextInt();
        }

//        int totalWeight = 82;
//
//        int[] weight = new int[]{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
//        int[] value = new int[]{20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1};


        int[] dp = new int[totalWeight+1];
        for (int i = 0; i < weight.length; i++) {
            for (int j = weight[i]; j <= totalWeight; j++) {
                dp[j] = Math.max(dp[j],dp[j-weight[i]] + value[i]);
            }
        }
        System.out.println(dp[totalWeight]);
    }
}
